// 原材料出库查询 -- wzhg
import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import AddPage from './addPage'
import PackScrapPage from './PackScrapPage'
import SplitScrapPage from './SplitScrapPage'

import ListDetail from './ListDetailPage.js'
import { fetchData } from '../../../components/AjaxConsumer'
const confirm = Modal.confirm;

export default class ListProCheckInPage extends Component{
    constructor(props) {
        super(props);
        this.state = {
            visible: false
        }
        //行操作列表-已弃用
        this.rowOperation = [

        ];
        //header 操作列表111
        this.headerOperation = [

            {
                handleName: 'create',
                showName: '创建',
                iconClass: 'plus',
                permission: 'car-add'
            },{
                handleName: 'packScrap',
                showName: '包装报废',
                iconClass: 'plus'
             },
             {
                 handleName: 'splitScrap',
                 showName: '拆分报废',
                 iconClass: 'plus'
              },{
                handleName: 'codeCreate',
                showName: '条码生成--按单',
                iconClass: 'edit',
                permission: 'car-createid'
            }
            // ,{
            //     handleName: 'info',
            //     showName: '条码详情',
            //     iconClass: 'plus',
            //     // permission: 'car-see'
            // }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'checkInId',
            data: [
                {
                    showName: 'checkInId',
                    columnName: 'checkInId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '登记单号',
                    columnName: 'checkInNo',
                    columnWidth: 130
                },{
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 130
                },{
                    showName: '品名',
                    columnName: 'productName',
                    columnWidth: 90
                },{
                    showName: '定量',
                    columnName: 'density',
                    columnWidth: 90
                },{
                    showName: '规格',
                    columnName: 'spec',
                    columnWidth: 90
                },{
                    showName: '生产机号',
                    columnName: 'machineNumber',
                    showOption: []
                },{
                    showName: '等级',
                    columnName: 'grade',
                    showOption:[
                        {
                            optionKey:'1',
                            optionShow:'一等品'
                        },{
                            optionKey:'2',
                            optionShow:'二等品'
                        },{
                            optionKey:'3',
                            optionShow:'处理品'
                        }
                    ]
                },{
                    showName: '级别',
                    columnName: 'level',
                    showOption:[
                        {
                            optionKey:'A',
                            optionShow:'A'
                        },{
                            optionKey:'B',
                            optionShow:'B'
                        },{
                            optionKey:'C',
                            optionShow:'C'
                        },{
                            optionKey:'D',
                            optionShow:'D'
                        }
                    ]
                }
                // ,{
                //     showName: '生产班组',
                //     columnName: 'productionTeam',
                //     showOption: [
                //     ]
                // }
                ,{
                    showName: '复卷班组',
                    columnName: 'rewindingTeam',
                    showOption:[
                    ]
                }
                // ,{
                //     showName: '生产类型',
                //     columnName: 'userDefined10'
                // }
                // ,{
                //     showName: '产品类型',
                //     columnName: 'type',
                //     showOption: [
                //         {
                //             optionKey: "0",
                //             optionShow: "正品"
                //         },{
                //             optionKey: "1",
                //             optionShow: "样品"
                //         }
                //     ]
                // }
                ,{
                    showName: '生产日期',
                    columnName: 'gmtProduct',
                    columnWidth: 120
                },{
                    showName: '登记数量（卷）',
                    columnName: 'amount',
                    columnWidth: 120
                },{
                    showName: '入库数量（卷）',
                    columnName: 'inAmount',
                    columnWidth: 120
                },{
                    showName: '是否生成条码',
                    columnName: 'userDefined2',
                    showOption:[
                        {
                            optionKey:'0',
                            optionShow:'否'
                        },{
                            optionKey:'1',
                            optionShow:'是'
                        }
                    ],
                    columnWidth: 140
                },{
                    showName: '大卷筒号',
                    columnName: 'bigNumber'
                },{
                    showName: '复卷个数',
                    columnName: 'rewindingNumber'
                },{
                    showName: '复卷次数',
                    columnName: 'rewindingCount'
                },{
                    showName: '创建人',
                    columnName: 'createBy',
                    columnWidth: 140
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreate',
                    columnWidth: 140
                },{
                    showName: '切割位序',
                    columnName: 'userDefined5',
                    columnHidden:true,
                    foreverHidden: true
                }
            ]
        };
        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        //      5、下拉框 type='disabled'
        this.searchComponentData = [
            {
                showName: '生产机号',
                name: 'machineNumber',
                type: 'select',
                optionList: []
                // url:'/base/dic/get/machine_number'
            },
            {
                showName: '是否生成条码',
                name: 'userDefined2',
                type: 'select',
                optionList: [//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'否'
                    },{
                        optionKey:'1',
                        optionShow:'是'
                    }
                ]
            },
            {
                showName: '生产班组',
                name: 'productionTeam',
                type: 'select',
                optionList: [//下拉框的信息
                ]
            },
            {
                showName: '复卷班组',
                name: 'rewindingTeam',
                type: 'select',
                optionList: [//下拉框的信息
                ]
            },
            {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList: [//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            },
            {
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList: [//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    },{
                        optionKey:'D',
                        optionShow:'D'
                    }
                ]
            }
            // ,{
            //     showName: '生产类型',
            //     name: 'userDefined10',
            //     type: 'select',
            //     optionList: [
            //         {
            //             optionKey:'',
            //             optionShow:''
            //         },{
            //             optionKey:'A',
            //             optionShow:'A'
            //         },{
            //             optionKey:'B',
            //             optionShow:'B'
            //         }
            //     ]
            // },{
            //     showName: '产品类型',
            //     name: 'type',
            //     type: 'select',
            //     optionList: [//下拉框的信息
            //         {
            //             optionKey:'',
            //             optionShow:''
            //         },{
            //             optionKey:'0',
            //             optionShow:'正品'
            //         },{
            //             optionKey:'1',
            //             optionShow:'样品'
            //         }
            //     ]
            // }
            ,{
                showName: '登记数量（卷）',
                name: 'amount',
                type:'number',
                maxName: 'amountMax',
                minName: 'amountMin'
            },{
                showName: '入库数量（卷）',
                name: 'inAmount',
                type: 'number',
                maxName: 'inAmountMax',
                minName: 'inAmountMin'
            },
            {
                showName: '大卷筒数量',
                name: 'bigNumber',
                type: 'number',
                maxName: 'bigNumberMax',
                minName: 'bigNumberMin'
            },{
                showName: '复卷个数',
                name: 'rewindingNumber',
                type: 'number',
                maxName: 'rewindingNumberMax',
                minName: 'rewindingNumberMin'
            },{
                showName: '复卷次数',
                name: 'rewindingCount',
                type: 'number',
                maxName: 'rewindingCountMax',
                minName: 'rewindingCountMin'
            },
            {
                name: 'gmtProduct',
                type: 'date',
                maxName: 'gmtProductMax',
                minName: 'gmtProductMin'
            },
            {
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin',
                showTime:'1'
            }
        ];

    }

    componentWillMount(){
        const machineOptions = {
            url: '/base/dic/get/machine_number',
            type: 'get'
        }
        fetchData(this, machineOptions, this.machineInitCallbackHandle);
        const teamsOptions = {
            url: '/base/team/getTeams',
            type: 'get'
        }
        fetchData(this, teamsOptions, this.teamsInitCallbackHandle);
    }

    machineInitCallbackHandle = (resData) => {
        let optionList = [];
        optionList.push('');
        resData.data.map((e, index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });
        this.tableColumn.data[6].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }
    teamsInitCallbackHandle = (resData) => {
        let optionList = [];
        optionList.push('');
        resData.data.map((e, index) => {
            let tmp = {};
            tmp.optionKey = e.teamCode;
            tmp.optionShow = e.teamName;
            optionList.push(tmp);
        });
        this.tableColumn.data[9].showOption = optionList;
        // this.searchComponentData[2].optionList = optionList;
        // this.tableColumn.data[10].showOption = optionList;
        this.searchComponentData[3].optionList = optionList;
    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'create'){
            this.createHandle(rowObj);
        }else if(strHandles === 'codeCreate'){
            this.codeCreateHandle(rowObj);
        }if(strHandles == 'doubleClick'){
            this.infoHandle(rowObj);
        }if(strHandles == 'info'){
            this.infoHandle(rowObj);
        }if(strHandles == 'packScrap'){
            this.packScrapHandle(rowObj);
        }if(strHandles == 'splitScrap'){
            this.splitScrapHandle(rowObj);
        }
    }

    // addHandle = () => {
    //     this.setState({
    //         formData:{},
    //         submitUrl:'/wmsrest/raw/rawHandOut/createOutOrder'
    //     })
    //     this.showModal();
    // }

    createHandle = () => {
        this.refs.addPage.addHandle();
    };
    packScrapHandle = () => {
        this.refs.packScrapPage.addHandle();
    };
    splitScrapHandle = () => {
        this.refs.splitScrapPage.addHandle();
    };
    // editHandle = (rowObj) => {
    //     // code不可编辑
    //     this.refs.rawEdit.getFormData[1].disable=true;
    //     if(rowObj.length == 0){
    //         Modal.error({
    //             title: '错误提示',
    //             content: '请选择一条数据',
    //         });
    //     }else if(rowObj.length > 1){
    //         Modal.error({
    //             title: '错误提示',
    //             content: '只能选择一条数据',
    //         });
    //     }else{
    //         this.refs.rawEdit.editHandle(rowObj[0].data);
    //     }
    // }

    codeCreateHandle = (rowObj) => {
         if(rowObj.length == 0){
             Modal.error({
                 title: '错误提示',
                 content: '请选择一条数据',
             });
         }else if(rowObj.length > 1){
             Modal.error({
                 title: '错误提示',
                 content: '只能选择一条数据',
             });
         }else{
             let checkInNo = rowObj[0].data.checkInNo;
             let checkInId = rowObj[0].data.checkInId;
             let userDefined2 = rowObj[0].data.userDefined2;
             if(userDefined2 == 1){
                Modal.error({
                    title: '错误提示',
                    content: '不可重复生成条码',
                });
             }else{
                const options = {
                    url: '/product/checkin/codeCreate',
                    condition: { checkInId:checkInId}
                };
   
                let _that = this;
                confirm({
                    title: '是否生成条码？',
                    onOk() {
                        fetchData(_that, options, _that.refreshHandle);
                        console.log("------------删除操作------------------")
                    },
                    onCancel() {
                        console.log("取消了删除操作")
                    },
                });
             }

         }
     }


    infoHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.listDetail.editHandle(rowObj[0].data);
        }
    };

    showModal = () => {
        this.setState({
            visible: true
        });
    }

    handleCancel = () => {
        this.setState({
            visible: false
        });
        this.refreshHandle();
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.proCheckInList.refreshHandle();
    }

    // componentWillMount() {
    //     const dicType = 'model_type';
    //     const options = {
    //         url: '/base/dic/get/' + dicType,
    //         type: 'get',
    //         condition: {}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options, this.dicInitCallBackHandle);
    // }

    // //下拉框 初始化
    // dicInitCallBackHandle = (resData) => {
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map((e, index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });
    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[5].showOption = optionList;
    //     this.searchComponentData[0].optionList = optionList;
    //     //this.setState({
    //     //    tableColumn: this.tableColumn,
    //     //    searchComponentData: this.searchComponentData
    //     //})

    // }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        
        return(
            <div>
                <ListBox
                    title="条码登记任务查询"
                    ref = 'proCheckInList'
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/checkin/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
                <AddPage
                    ref="addPage"
                    refreshHandle = {this.refreshHandle}
                />

                <PackScrapPage
                    ref="packScrapPage"
                    refreshHandle = {this.refreshHandle}
                />

                <SplitScrapPage
                    ref="splitScrapPage"
                    refreshHandle = {this.refreshHandle}
                />

                <ListDetail
                    ref="listDetail"
                    refreshHandle = {this.refreshHandle}
                />

            </div>
        )

    }

}